package com.qiaoan.back.controller.sys;

import com.qiaoan.back.controller.BaseController;
import com.qiaoan.back.enums.ResultCode;
import com.qiaoan.back.model.sys.UserModel;
import com.qiaoan.back.service.sys.UserService;
import com.qiaoan.constant.StringConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("/sysuser")
public class UserController extends BaseController {
	
	@Autowired
	private UserService service ;

	@RequestMapping(value = "/index", method = { RequestMethod.GET })
	public String list(Model model, HttpServletRequest request,
					   HttpServletResponse response) throws Exception {


		return "sys/user/list";

	}

	@RequestMapping(value = "/view", method = { RequestMethod.GET })
	public String view(Model model, HttpServletRequest request,
					   HttpServletResponse response) throws Exception {


		return "sys/user/view";

	}

	@RequestMapping(value = "/add", method = { RequestMethod.POST})
	public void insert(Model model, HttpServletRequest request,
					HttpServletResponse response,UserModel user) throws Exception {


		//后台校验
		logger.info("***********************model:"+user);
		int result = service.insert(user);
		//处理结果
		if (result > 0){

			printJson(response, ResultCode.Success, StringConstant.INSERT_MSG);
		}else{
			printJson(response,ResultCode.Fail,StringConstant.OPERATE_FAILURE_MSG);
		}

	}

}
